/**
* 匠言知识付费v2.0.0
* Author: 山西匠言网络科技有限公司
* 这不是一个免费软件，它受限于许可条款，你可以访问https://www.zsfzxkc.cn/获取更多详细信息。
* This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
*/
<template>
	<view class="container">
		<!-- 当前人数显示 -->
<!-- 		<view class="p_num">
			<uni-transition ref="ani" custom-class="transition" :mode-class="modeClass" duration="800" timingFunction='ease-in-out' :show="pnum_show">
				<text class="p_num_text">当前共{{pnum}}人在线</text>
			</uni-transition>
		</view> -->
		<!-- 自定义底部start -->
		<jy-navbar :current_index='current_ind'></jy-navbar>
		<!-- 自定义底部end -->
		<view class="kpdh" v-if="ad_close">
			<image :src="base_set.qrcode" mode="aspectFit"></image>
			<view>{{base_set.gzinfo}}</view>
			<image class="closebtn" src="../../static/close.png" mode="aspectFit" @click="closebtn"></image>
		</view>
		<!-- 计算手机状态栏的高度 -->
		<!-- #ifndef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-ALIPAY -->
		<view class="status_bar">

		</view>
		<!-- #endif -->

		<!-- 头部 -->
		<view class="header" :class="[{newheader:navBarFixed},{changebf:huifu},{newstyle:mpsh}]"
			:style="{'background-color':swiper_bgcolor}">
			<!-- 分类 -->
			<view class="header-list" v-if="base_set.diypage.is_flshow==1">
				<scroll-view class="list" scroll-x="true">
					<view class="list-box">
						<view class="list-item" @click="postIndexGoods(0,0)">
							
							<view class="list-item-top" :class="[{fangda: 0 == current}, {newview: navBarFixed}]">推荐
							</view>
							
							<view class="list-item-bottom"
								:class="[{hengxian: 0 == current}, {newhengxian: navBarFixed}]"></view>
						</view>

						<view class="list-item" v-for="(item,index) in fls" :key="index"
							@click="postIndexGoods(item.id,index+1)">
							
							<view class="list-item-top"
								:class="[{fangda: (index+1) == current}, {newview: navBarFixed}]">{{item.title}}</view>
							
							<view class="list-item-bottom"
								:class="[{hengxian: (index+1) == current}, {newhengxian: navBarFixed}]"
								style="transition: .3s"></view>
						</view>

					</view>
				</scroll-view>
				<view class="icon" :fls="fls" @click="goListPage">
					<image v-if="!navBarFixed" src="../../static/fenleixuanzhong.png" mode="aspectFit"></image>
					<image v-else src="../../static/fenleixuanzhong1.png" mode="aspectFit"></image>
				</view>
			</view>

			<!-- 搜索框 -->
			<view class="header-input" v-if="base_set.diypage.is_searchshow==1">
				<view class="header-input-search" :class="{newinput: navBarFixed}">
					<input v-model.trim="keyword" type="text"
						:placeholder="!navBarFixed?'请输入搜索内容':'想找什么不妨搜搜看'" :placeholder-style="navBarFixed?'color:#4b89ff;font-size:22rpx;':'font-size:22rpx;'"/>
					<image @click="postSearchCourse" :src="!navBarFixed?'../../static/search.png':'../../static/search1.png'" mode="aspectFit"></image>
				</view>
				<view class="header-input-msg">
					<uni-badge :text="dot_text" type='error' size="small"  absolute="rightTop">
					<image @click="navigate('message')" :src="!navBarFixed?'../../static/msg.png':'../../static/msg1.png'" mode="aspectFit">
					</image>
					</uni-badge>
				</view>
			</view>
		</view>

		<view v-if="current == 0">
			<!-- 轮播图 -->
			<view class="swiper" :class="[{newheader:navBarFixed},{changebf:huifu},{newstyle1:mpsh}]"
				:style="{'background-color':swiper_bgcolor}">
				<swiper :indicator-dots="true" :autoplay="true" :interval="2000" :duration="1000" circular="true" easing-function="easeInOutCubic"
					@change="swiper_change">
					<swiper-item v-for="item in images" :key="item.id">
						<view class="swiper-item">
							<image :src="item.thumb" mode="aspectFill"></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<!-- 图标 -->
			<swiper class="iconsswiper" :autoplay="true" :indicator-dots="true" :interval="5000" :duration="1000" circular="true" easing-function="easeInOutCubic"
				v-if="base_set.diypage.is_dhlshow==1">
			<swiper-item class="icons">
				<view class="icons-list" @click="navigate('tutor-list')">
					<image :src="ICON_URL+'daoshi.png'" mode="aspectFit"></image>
					<text>导师</text>
				</view>
				<view class="icons-list" @click="navigate('shopping')">
					<image :src="ICON_URL+'mall.png'" mode="aspectFit"></image>
					<text>商城</text>
				</view>
				<view class="icons-list" @click="goCourseList">
					<image :src="ICON_URL+'live.png'" mode="aspectFit"></image>
					<text>直播</text>
				</view>
				<view class="icons-list" @click="jiFen">
					<image :src="ICON_URL+'jigou.png'" mode="aspectFit"></image>
					<text>机构</text>
				</view>
				<view class="icons-list" @click="navigate('exam1')">
					<image :src="ICON_URL+'exam.png'" mode="aspectFit"></image>
					<text>考试</text>
				</view>
				<view class="icons-list" @click="navigate('filedownload')">
					<image :src="ICON_URL+'download.png'" mode="aspectFit"></image>
					<text>资源下载</text>
				</view>
				<view class="icons-list" @click="navigate('ancient-works')">
					<image :src="ICON_URL+'ebook.png'" mode="aspectFit"></image>
					<text>电子书</text>
				</view>
				<view class="icons-list" @click="navigate('bisai')">
					<image :src="ICON_URL+'bisai.png'" mode="aspectFit"></image>
					<text>比赛</text>
				</view>
				<view class="icons-list" @click="navigate('perform')">
					<image :src="ICON_URL+'perform.png'" mode="aspectFit"></image>
					<text>演出</text>
				</view>
				<view class="icons-list" @click="navigate('sidonghui')">
					<image :src="ICON_URL+'sidonghui.png'" mode="aspectFit"></image>
					<text style="color: orangered;">私董会</text>
				</view>
			</swiper-item>
			<swiper-item class="icons">
				<view class="icons-list" @click="navigate('wenda')">
					<image :src="ICON_URL+'zixun.png'" mode="aspectFit"></image>
					<text>付费问答</text>
				</view>
				<view class="icons-list" @click="navigate('exam')">
					<image :src="ICON_URL+'xinli-exam.png'" mode="aspectFit"></image>
					<text style="color: red;">心理测评</text>
				</view>
				<view class="icons-list" @click="navigate('wiki')">
					<image :src="ICON_URL+'wiki.png'" mode="aspectFit"></image>
					<text>百科</text>
				</view>
				<view class="icons-list" @click="postSearchCourse('free')">
					<image :src="ICON_URL+'free.png'" mode="aspectFit"></image>
					<text>免费</text>
				</view>
				<view class="icons-list" @click="postSearchCourse('new')">
					<image :src="ICON_URL+'new.png'" mode="aspectFit"></image>
					<text>最新</text>
				</view>
				<view class="icons-list" @click="postSearchCourse('hot')">
					<image :src="ICON_URL+'hot.png'" mode="aspectFit"></image>
					<text>热门</text>
				</view>
				<view class="icons-list" @click="navigate('vip')">
					<image :src="ICON_URL+'vip.png'" mode="aspectFit"></image>
					<text>会员</text>
				</view>
				<view class="icons-list" @click="navigate('Headlines-index')">
					<image :src="ICON_URL+'news.png'" mode="aspectFit"></image>
					<text>头条</text>
				</view>
				<view class="icons-list" @click="navigate('doudouvideo')">
					<image :src="ICON_URL+'doudou.png'" mode="aspectFit"></image>
					<text>抖抖短视频</text>
				</view>
				<view class="icons-list" @click="navigate('dazhuanpan')">
					<image :src="ICON_URL+'bigwheel.png'" mode="aspectFit"></image>
					<text>幸运大转盘</text>
				</view>
			</swiper-item>
			<swiper-item class="icons">
				<view class="icons-list" @click="navigate('sign-in')">
					<image :src="ICON_URL+'sign.png'" mode="aspectFit"></image>
					<text>签到</text>
				</view>
				<view class="icons-list" @click="navigate('promotion-code')">
					<image :src="ICON_URL+'tgm.png'" mode="aspectFit"></image>
					<text>推广码</text>
				</view>
			</swiper-item>
			</swiper>

			<!-- 限时秒杀 -->
			<view class="timelimit" v-if="base_set.diypage.is_seckill==1">
				<view class="timelimit-top">
					<image src="../../static/miaosha.png" mode="aspectFit"></image>
					<uni-countdown color="#FFFFFF" background-color="#333" :show-day="false" :hour="killhour"
						:minute="killminute" :second="killsecond"></uni-countdown>
					<text class="btn" @click="navigate('seckill')">查看更多></text>
				</view>
				<scroll-view class="timelimit-bottom" scroll-x="true">
					<view class="timelimit-bottom-list" v-for="(item, index) in robBuyList" :key="index"
						@click="plugin_navigate(item.goodstype,item.goodsid,'seckill')">
						<view class="timelimit-bottom-list-top">
							<image :src="item.goodsinfo.thumb" mode="aspectFill"></image>
						</view>
						<view class="timelimit-bottom-list-center">{{item.goodsname}}</view>
						<view class="timelimit-bottom-list-bottom">
							<text>￥{{item.goodsinfo.price}}</text>
							<text>￥{{item.price}}</text>
							<text></text>
						</view>
					</view>
				</scroll-view>
			</view>



			<!-- 超级拼团 -->
			<view class="super" v-if="base_set.diypage.is_pintuan==1">
				<view class="super-top">
					<image src="../../static/pintuan.png" mode="aspectFit"></image>
					<text class="btn" @click="navigate('super-pt')">查看更多></text>
					<view>{{ptNum}}人正在参与拼团</view>
				</view>
				<scroll-view class="super-bottom" scroll-x="true">
					<view class="super-bottom-list" v-for="(item, index) in ptInfo" :key="index"
						@click="plugin_navigate(item.goodstype,item.goodsid,'pintuan')">
						<view class="super-bottom-list-top">
							<image :src="item.thumb" mode="aspectFill"></image>
						</view>
						<view class="super-bottom-list-center">{{item.goodsname}}</view>
						<view class="super-bottom-list-bottom">
							<text>￥{{item.price}}</text>
							<text>￥{{item.goodsinfo.price}}</text>
							<text>开团</text>
						</view>
					</view>
				</scroll-view>
			</view>
			
			<!-- 推荐机构 -->
			<view class="recommend" v-if="base_set.diypage.is_jigoushow==1">
				<view class="recommend-top">
					<image src="../../static/tjjg.png" mode="aspectFit"></image>
					<text class="btn" @click="navigate('training-agency')">查看更多></text>
				</view>
				<view class="recommend-bottom">
					<view class="recommend-bottom-info" v-for="(item, index) of tuijianjigou" :key="item.id"
						@click="pxb_detail(item.id)">
						<image :src="item.main_thumb" mode="aspectFit"></image>
						<view class="recommend-bottom-info-list">
							<text>{{item.name}}</text>
							<text>{{item.classify}}</text>
							<text>{{item.address}}</text>
						</view>
					</view>
				</view>
			</view>
			
			<!-- 课程专场 -->
			<view class="course" v-if="base_set.diypage.is_zcshow==1">
				<view class="course-top">
					<image src="../../static/kczc.png" mode="aspectFit"></image>
					<text class="btn" @click="navigate('course-list','indextj')">查看更多></text>
				</view>
				<view class="course-bottom">
					<view class="course-bottom-list" v-for="(item, index) in index_courseTJ" :key="index"
						@click="goCourseDetails(item.id)">
						<image :src="item.thumb" mode="aspectFill"></image>
						<text>{{item.menuname}}</text>
						<text>共{{item.ksnum}}课时<text>|</text>{{item.viewnum}}人已学</text>
						<view class="course-bottom-list-vip" v-if="item.lid !=0 ">
							{{item.levelname}}
						</view>
						<view class="course-bottom-list-vip" v-if="item.lid !=0 ">
							{{item.levelname}}
						</view>
						<view class="course-bottom-list-type">
							{{item.jgid == 0?'平台':'机构'}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<!-- 轮播图 -->
			<view class="swiper" :class="[{newheader:navBarFixed},{changebf:huifu}]"
				:style="{'background-color':swiper_bgcolor}">
				<swiper :indicator-dots="true" :autoplay="true" :interval="2000" :duration="1000" circular="true" easing-function="easeInOutCubic"
					@change="swiper_change">
					<swiper-item v-for="item in images" :key="item.id">
						<view class="swiper-item">
							<image :src="item.thumb" mode="aspectFit"></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<!-- 二级分类列表 -->
			<view class="course11">
				<view class="course11-list">
					<view class="course11-list-item" v-for="(son_fl, index) in son_fls" :key="son_fl.id"
						@click="sonflCourseList(son_fl.id)">
						<text>{{son_fl.title}}</text>
					</view>
					<view class="course11-list-item" v-if="son_fls.length > 0">
						<text>更多</text>
					</view>
					<!-- v-if="index >= 6" -->
					<view class="course11-list-item" v-if="son_fls.length >= 6">
						<image src="../../static/xiangxia1.png" mode="aspectFit" style="width: 24upx; height: 16upx;">
						</image>
					</view>
				</view>
			</view>
			<!-- 课程推荐 -->
			<view class="kecheng">
				<view class="kecheng-top">
					<image src="../../static/kechengtuijian.png" mode="aspectFit"></image>
					<view @click="declick('tj')">
						<text>换一批</text>
						<image :class="{an: isPlaying, pause: isPaused}" src="../../static/huanyipi.png"
							mode="aspectFit"></image>
					</view>
				</view>
				<view class="kecheng-bottom">
					<view class="kecheng-bottom-list" v-for="(item, index) in courseTJ" :key="index"
						@click="goCourseDetails(item.id)">
						<image :src="item.thumb" mode="aspectFit"></image>
						<text>{{item.menuname}}</text>
						<view>
							<text>共{{item.ksnum}}课时</text>
							<text>|</text>
							<text>{{item.viewnum}}人已学</text>
						</view>
						<view class="kecheng-bottom-list-vip" v-if="item.lid !=0 ">
							{{item.levelname}}
						</view>
					</view>
				</view>
			</view>
			<!-- 独家精选 -->
			<view class="exclusive">
				<view class="exclusive-top">
					<image src="../../static/dujiajingxuan.png" mode="aspectFit"></image>
					<view @click="declick('jx')">
						<text>换一批</text>
						<image :class="{an: isPlaying1, pause: isPaused1}" src="../../static/huanyipi.png"
							mode="aspectFit"></image>
					</view>
				</view>
				<view class="exclusive-bottom">
					<view class="exclusive-bottom-list" v-for="(item, index) in dujiaList" :key="index"
						@click="goCourseDetails(item.id)">
						<image class="img" :src="item.thumb" mode="aspectFit"></image>
						<view class="span">
							<text>{{item.menuname}}</text>
							<text>{{item.jianjie}}</text>
							<view class="span-view">
								<text>{{item.tinfo.imgname}}</text>
							</view>
						</view>
						<view class="exclusive-bottom-list-vip" v-if="item.lid !=0 ">
							{{item.levelname}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import {
		postSeckill
	} from '@/request/seckill.js'
	import {
		getIndexListInfo,
		postIndexGoods,
		postDhHyp
	} from '@/request/index'
	import {
		h5wx_login
	} from '@/request/checkUserinfo'
	export default {

		data() {
			return {
				keyword: '',
				fls: [],
				current: 0,
				navBarFixed: false,
				huifu: false,
				images: [],
				HOST_URL: uni.HOST_URL,
				coursemenus: [],
				son_fls: [],
				index: 0,
				swiper_bgcolor: '#4b89ff',
				robBuyList: {},
				killhour: 0,
				killminute: 0,
				killsecond: 0,
				ptInfo: {},
				ptNum: '',
				tuijianjigou: [],
				index_courseTJ: [], //主页课程推荐
				courseTJ: [], // 分类课程推荐列表
				dujiaList: [], // 独家精选列表
				flid: '', // 这个变量用于传值
				isPlaying: false,
				isPaused: false,
				isPlaying1: false,
				isPaused1: false,
				page: 0,
				page1: 0,
				base_set: [],
				ad_close: false,
				freetext: '免费',
				jiFentext: '积分',
				current_ind:1,
				dot_text:0,
				has_notReadMsg:true,
				mpsh:false,
				pnum_show:false,//人数显示动画开关
				modeClass: 'fade',
				pnum:0,
				ICON_URL:uni.ICON_URL,
			}
		},
		onLoad() {
			// #ifdef MP-TOUTIAO
			this.footerList[1].page_route = '/pages/sign-in/sign-in';
			this.footerList[1].name = '签到';
			// #endif
			this.base_set = uni.getStorageSync('base_set');

		},
		onShareTimeline(){
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			var pid;
			if (userinfo.uid == '' || !userinfo.uid) {
				pid = userinfo.uid
			}else{
				pid = 0
			}
			return {
			  title: base_set.share_title,
			  query: 'pid='+pid,
			  imageUrl: base_set.share_icon
			}
		},
		onShareAppMessage(res) {
			// #ifdef MP
			uni.showShareMenu({
			  withShareTicket: true,
			  menus: ['shareAppMessage', 'shareTimeline']
			})
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if (userinfo.uid == '' || !userinfo.uid) {
				uni.navigateTo({
					url: '../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			} else {
				if (res.from === 'button') {

				}
				return {
					title: base_set.share_title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
			// #endif
		},
		onPageScroll(object) {
			let scrollTop = object.scrollTop;
			if (scrollTop > 30) {
				this.navBarFixed = true
				this.huifu = false
			} else {
				this.navBarFixed = false
				this.huifu = true
			}
		},
		onShow() {
			// 在线人数动画
			// setTimeout(()=>{
			// 	this.pnum_show = true;
			// 	this.modeClass = ['fade','slide-right'];
			// },3000)
			// setTimeout(()=>{
			// 	this.pnum_show = false;
			// 	this.modeClass = ['fade','slide-left'];
			// },8000)
			const BASE_URL = uni.BASE_URL
			uni.request({
				url: BASE_URL+'index/set/base_set',
				method:'GET',
				success:(res) =>{
					console.log(res.data);
					this.base_set = res.data.data;
					// #ifdef MP-TOUTIAO || MP-BAIDU || MP-KUAISHOU || MP-ALIPAY || MP-JD
					this.base_set.diypage.is_dhlshow = 0
					this.base_set.diypage.is_seckill = 0
					this.base_set.diypage.is_pintuan = 0
					this.base_set.diypage.is_jigoushow = 0
					// #endif
					this.getIndexInfo();
					let base_set = res.data.data;
					this.mpsh = false
					uni.setNavigationBarTitle({
						title: base_set.title
					});
					
					this.dot_text = getApp().globalData.dot_text;
					// #ifdef H5
					var ua = window.navigator.userAgent.toLowerCase();
					if (ua.match(/micromessenger/i) == 'micromessenger') {
						var userinfo=uni.getStorageSync('userinfo')
						if(!userinfo && !userinfo.userdata){
							h5wx_login()
						}
					}
					// #endif

					var date = new Date()
					var hour = date.getHours() < 10 ? "0" + date.getHours() + ':00' : date.getHours() + ':00'
					this.goodslist(hour, '')
					this.ptNum = Math.random().toFixed(2) * 4000 + 2000;
					var nowhour1 = (date.getHours() + 1) < 10 ? "0" + (date.getHours() + 1) + ':00' : (date.getHours() + 1) + ':00'
					var date1 = new Date(date.toLocaleDateString() + ' ' + nowhour1)
					var time1 = date1.getTime()
					var nowtime = date.getTime()
					var second1 = Math.floor((time1 - nowtime) / 1000)
					this.formatSecToStr(second1)
					
					// 计时关闭弹窗
					// let base_set = this.base_set
					let adclosetime = uni.getStorageSync('adclosetime')
					if (base_set) {
						if (base_set.is_gz == 1) {
							if (adclosetime) {
								if (nowtime - adclosetime > base_set.jgtime * 1000) {
									this.ad_close = true
								} else {
									this.ad_close = false
								}
							} else {
								this.ad_close = true
							}
						}
						// #ifdef MP
						if (this.base_set.smallapp.is_sh == 0) {
							this.freetext = this.base_set.smallapp.freetext
						}
						// #endif
						// #ifndef MP
						this.freetext = this.base_set.freetext
						// #endif
					}
					
				},
				fail:(res)=> {
					console.log(res.data);
				}
			});
		},
		onReady() {
			this.pnum = getApp().globalData.pnum;//显示当前在线人数
		},
		methods: {
			pxb_detail(id) {
				uni.navigateTo({
					url: '/pages/sub/organization/organization?id=' + id
				})
			},
			closebtn() {
				var date = new Date()
				var nowtime = date.getTime()
				this.ad_close = false
				uni.setStorageSync('adclosetime', nowtime)
			},
			declick(type) {

				if (type == 'tj') {
					this.isPlaying = true
					console.log('loading')
					this.isPaused = false
					setTimeout(() => {
						var data = {
							flid: this.flid,
							page: this.page,
							type: type ? type : ''
						}
						postDhHyp(data).then(res => {
							console.log(res.data)
							if (res.data.code == 0) {
								this.courseTJ = res.data.data
							}
						})
						console.log('end')
						this.isPaused = true
					}, 1500)
					this.page++
				} else {
					this.isPlaying1 = true
					console.log('loading')
					this.isPaused1 = false
					setTimeout(() => {
						var data = {
							flid: this.flid,
							page: this.page1,
							type: type ? type : ''
						}
						postDhHyp(data).then(res => {
							console.log(res.data)
							if (res.data.code == 0) {
								this.dujiaList = res.data.data
							}
						})
						console.log('end')
						this.isPaused1 = true
					}, 1500)
					this.page1++
				}
			},
			formatSecToStr(seconds) {
				let daySec = 24 * 60 * 60;
				let hourSec = 60 * 60;
				let minuteSec = 60;
				let dd = Math.floor(seconds / daySec);
				let hh = Math.floor((seconds % daySec) / hourSec);
				let mm = Math.floor((seconds % hourSec) / minuteSec);
				let ss = seconds % minuteSec;
				if (dd > 0) {

				}
				if (hh > 0) {
					this.killhour = hh
				}
				if (mm > 0) {
					this.killminute = mm
				}
				if (ss > 0) {
					this.killsecond = ss
				}
			},
			// 秒杀列表
			goodslist(hour, key) {

				postSeckill({
					timeslot: hour
				}).then(res => {
					this.robBuyList = res.data.data.data
				})
			},
			plugin_navigate(goodstype, goodsid, action) {
				var e, path;
				if (goodstype == 'course') {
					e = 'course-details'
					uni.navigateTo({
						url: `/pages/${e}/${e}?menuid=${goodsid}&action=${action}`
					});
				} else {
					if (goodstype == 'mall') {
						e = 'shop-details'
						path = '/pages/mall/'
					} else if (goodstype == 'pxb') {
						e = 'agency-course-details'
						path = '/pages/sub/'
					}
					uni.navigateTo({
						url: path + `${e}/${e}?id=${goodsid}&action=${action}`
					});
				}
			},
			// 去列表页面
			goListPage() {
				uni.navigateTo({
					url: `/pages/list-page/list-page?goodstype=course`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			// 去课程详情页面
			goCourseDetails(id) {
				uni.navigateTo({
					url: `/pages/course-details/course-details?menuid=${id}`
				})
			},
			swiper_change(e) {
				// console.log('swiper',e)
				uni.setNavigationBarColor({
				    frontColor: '#ffffff',
				    backgroundColor: this.images[e.detail.current].maincolor,
				    animation: {
						duration:500,
				        timingFunc: 'easeInOut'
				    }
				})
				this.swiper_bgcolor = this.images[e.detail.current].maincolor
			},

			// 页面跳转
			navigate(e, param) {
				if(e == 'filedownload'){
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if(e == 'wenda'){
					uni.showToast({
						title:'请购买商用版'
					})
					
				}
				else if(e == 'sidonghui'){
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if(e == 'doudouvideo'){
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if(e == 'wiki'){
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'course-list') {
					uni.navigateTo({
						url: '/pages/' + e + '/' + e + '?moretype=' + param
					})
				} else if (e == 'training-agency') {
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'exam') {
					uni.showToast({
						title:'请购买商用版'
					})
				} 
				else if (e == 'exam1') {
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'shopping') {
					uni.showToast({
						title:'请购买商用版'
					})
				} else if (e == 'ancient-works') {
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'Headlines-index') {
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'dazhuanpan') {
					uni.showToast({
						title:'请购买商用版'
					})
				}
				else if (e == 'tutor-list') {
					uni.navigateTo({
						url: '/pages/teacher-center/' + e + '/' + e
					})
				} else if (e == 'promotion-code'){
					// #ifdef APP-PLUS
					 
					plus.share.getServices(shareList => {
						let shareWx = shareList.find(val => val.id == 'weixin')
						if (shareWx) {
							shareWx.launchMiniProgram({
								id: this.base_set.smallapp.ysid
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: "未安装微信,无法打开对应小程序"
							})
						}
					}, e => {
						uni.showToast({
							icon: 'none',
							title: "获取分享服务列表失败:" + JSON.stringify(e)
						})
					})
					
					//#endif
					// #ifndef APP-PLUS
					uni.navigateTo({
						url: '/pages/fenxiao/' + e + '/' + e
					})
					//#endif
				}else{
					uni.navigateTo({
						url: '/pages/' + e + '/' + e
					})
				}
			},
			// 去课程列表页面
			goCourseList() {
				// #ifdef MP
				if (this.base_set.smallapp.is_sh == 1) {
					uni.navigateTo({
						url: `/pages/course-list/course-list?keyword=free`
					});
				} else {
					uni.navigateTo({
						url: `/pages/course-list/course-list?media=live&goodstype=course`
					});
				}
				// #endif
				// #ifndef MP
				uni.navigateTo({
					url: `/pages/course-list/course-list?media=live&goodstype=course`
				});
				// #endif
			},

			jiFen() {
				// #ifdef MP
				if (this.base_set.smallapp.is_sh == 1) {
					uni.navigateTo({
						url: `/pages/credits-exchange/credits-exchange`
					});
				} else {
					uni.navigateTo({
						url: `/pages/sub/training-agency/training-agency`
					});
				}
				// #endif
				// #ifndef MP
				uni.navigateTo({
					url: `/pages/sub/training-agency/training-agency`
				});
				// #endif
			},
			// 获取轮播图和列表信息
			getIndexInfo() {
				uni.showNavigationBarLoading();
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/index/index?type=mobile',
					method:'GET',
					success:(res) =>{
						console.log(res.data);
						uni.hideNavigationBarLoading();
						this.images = res.data.data.ads
						this.fls = res.data.data.classify
						this.index_courseTJ = res.data.data.courses
						this.ptInfo = res.data.data.pt
						if (this.ptInfo) {
							this.ptInfo.forEach(item => {
								var thumb = item.goodsinfo.thumb.split(',')
								item.thumb = thumb[0]
							})
						}
						this.tuijianjigou = res.data.data.pxjg
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},

			// 获取首页分类列表信息
			postIndexGoods(id, key) {
				this.current = key
				this.flid = id
				getIndexListInfo({
					flid: id
				}).then(res => {
					this.son_fls = res.data.data.son_fl
				})
				postIndexGoods({
					goods_label: 'is_tj',
					flid: id
				}).then(res => {
					if (res.data.code == 0) {
						this.courseTJ = res.data.data
					} else {
						this.courseTJ = []
					}
				})
				postIndexGoods({
					goods_label: '',
					flid: id
				}).then(res => {
					if (res.data.code == 0) {
						this.dujiaList = res.data.data
					} else {
						this.dujiaList = []
					}
				})
			},
			sonflCourseList(sonid) {
				uni.navigateTo({
					url: `/pages/course-list/course-list?flid=${this.flid}&sonflid=${sonid}&goodstype=course`
				})
			},
			postSearchCourse(e) {
				var keyword
				if (e == 'hot' || e == 'new' || e == 'free') {
					keyword = e
				} else {
					keyword = this.keyword
					if (keyword == '') {
						uni.showToast({
							title: '搜索内容不能为空',
							icon: 'none'
						});
						return false
					}
				}
				uni.navigateTo({
					url: `/pages/course-list/course-list?keyword=${keyword}`
				});
			},
			color_change() {
				const ctx = uni.createCanvasContext('myCanvas')
				let src = this.images[0].thumb
				uni.downloadFile({
					url: src,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.getImageInfo({
							src: filePath,
							success: function(image) {
								ctx.drawImage(filePath, 0, 0, 375, 138.5)
								ctx.draw()
								setTimeout(function() {
									uni.canvasGetImageData({
										canvasId: 'myCanvas',
										x: 0,
										y: 0,
										width: 50,
										height: 50,
										success(res) {
											let imgdata = res.data
											var arr = []
											var i = 0,
												len = res.data.length
											for (i; i < len; i += 4) {
												arr.push(imgdata[i] + ',' +
													imgdata[i + 1] + ',' +
													imgdata[i + 2])
											}
											if (arr != []) {
												var obj = {};
												for (var j = 0, l = arr.length; j <
													l; j++) {
													var item = arr[j];
													obj[item] = (obj[item] + 1) ||
														1;
												}
												console.log(obj)
												var keys = Object.keys(obj)
												var maxNum = 0,
													maxEle
												for (var i = 0, l = keys
													.length; i < l; i++) {
													if (obj[keys[i]] > maxNum) {
														maxNum = obj[keys[i]]
														maxEle = keys[i]
													}
												}
												console.log(maxEle)
											}
										}
									})
								}, 500)
							}
						});
					}
				});
			},
		}
	}
</script>


<style lang="less">
	@import './index.less';
	@import './goods-course.less';

	@keyframes rotation {
		from {
			transform: rotate(0deg);
		}

		to {
			transform: rotate(720deg);
		}
	}
	.maxWidth{flex:1;}
	.an {
		animation: rotation 2s infinite linear;
	}

	.pause {
		animation-play-state: paused;
	}
	.p_num{
		width: 100%;
		position: fixed;
		display: flex;
		align-items: center;
		justify-content: center;
		top:0;
		left:0;
		z-index: 99999999;
		color: aqua;
	}
	.p_num_text{
		padding: 3rpx 30rpx;
		background-image:linear-gradient(to right,#eee 0%,#4b89ff 50%,transparent 100%);
		color: #fff;
		border-radius: 30rpx;
		font-size: 26rpx;
	}
</style>
